package arithmetic2;

import utils.PrintUtil;

/**
 * Created by AJie on 2019/8/28
 * Function :
 *删除排序数组中的重复项
 * https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
 */
public class T_026_RemoveRepeatSortedArray {
    public static void main(String[] args) {
        int[] nums ={1,2,3,3,4,4,5,5,5};
        System.out.println(removeDuplicates(nums));
        PrintUtil.print(nums);
    }

    //双指针算法
    public static int removeDuplicates(int[] nums) {
        if (nums==null || nums.length<1)return 0;
        int i = 0;
        for (int j = 1; j < nums.length; j++) {
            if (nums[j] != nums[i]) {
                i++;
                nums[i] = nums[j];
            }
        }
        return i + 1;
    }
}
